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

Optimize stats and rpc #97

Merged
merged 2 commits into from
Oct 11, 2022
Merged
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
14 changes: 13 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ all: build
lint:
golangci-lint run ./...

build:
build: rpc/rpc.pb.go stats/stats.pb.go
$(GO) build -v ./...
# Build crit binary
$(MAKE) -C crit bin/crit
Expand All @@ -21,6 +21,18 @@ coverage:
codecov:
$(MAKE) -C test codecov

rpc/rpc.proto:
curl -sSL https://raw.githubusercontent.com/checkpoint-restore/criu/master/images/rpc.proto -o $@

rpc/rpc.pb.go: rpc/rpc.proto
protoc --go_out=. --go_opt=M$^=rpc/ $^

stats/stats.proto:
curl -sSL https://raw.githubusercontent.com/checkpoint-restore/criu/master/images/stats.proto -o $@

stats/stats.pb.go: stats/stats.proto
protoc --go_out=. --go_opt=M$^=stats/ $^

vendor:
GO111MODULE=on $(GO) mod tidy
GO111MODULE=on $(GO) mod vendor
Expand Down
3 changes: 2 additions & 1 deletion crit/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ update-proto:
rm ./images/*.proto || true
git clone --depth 1 --branch master https://github.com/checkpoint-restore/criu criu-temp
cp criu-temp/images/*.proto ./images/
rm -rf criu-temp
# rpc.proto is not an image and it is used only to communicate criu-service and swrk.
rm -rf criu-temp images/rpc.proto
# To prevent namespace conflict with proto files
# in github.com/letsencrypt/boulder, we prepend
# a prefix to the filenames.
rst0git marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
8 changes: 4 additions & 4 deletions features.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package criu
import (
"fmt"

"github.com/checkpoint-restore/go-criu/v6/crit/images"
"github.com/checkpoint-restore/go-criu/v6/rpc"
)

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

func (c *Criu) FeatureCheck(features *images.CriuFeatures) (*images.CriuFeatures, error) {
func (c *Criu) FeatureCheck(features *rpc.CriuFeatures) (*rpc.CriuFeatures, error) {
resp, err := c.doSwrkWithResp(
images.CriuReqType_FEATURE_CHECK,
rpc.CriuReqType_FEATURE_CHECK,
nil,
nil,
features,
Expand All @@ -37,7 +37,7 @@ func (c *Criu) FeatureCheck(features *images.CriuFeatures) (*images.CriuFeatures
return nil, err
}

if resp.GetType() != images.CriuReqType_FEATURE_CHECK {
if resp.GetType() != rpc.CriuReqType_FEATURE_CHECK {
return nil, fmt.Errorf("Unexpected CRIU RPC response")
}

Expand Down
40 changes: 20 additions & 20 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"strconv"
"syscall"

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

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

func (c *Criu) doSwrk(reqType images.CriuReqType, opts *images.CriuOpts, nfy Notify) error {
func (c *Criu) doSwrk(reqType rpc.CriuReqType, opts *rpc.CriuOpts, nfy Notify) error {
resp, err := c.doSwrkWithResp(reqType, opts, nfy, nil)
if err != nil {
return err
Expand All @@ -99,10 +99,10 @@ func (c *Criu) doSwrk(reqType images.CriuReqType, opts *images.CriuOpts, nfy Not
return nil
}

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

req := images.CriuReq{
req := rpc.CriuReq{
Type: &reqType,
Opts: opts,
}
Expand Down Expand Up @@ -135,7 +135,7 @@ func (c *Criu) doSwrkWithResp(reqType images.CriuReqType, opts *images.CriuOpts,
return nil, err
}

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

respType := resp.GetType()
if respType != images.CriuReqType_NOTIFY {
if respType != rpc.CriuReqType_NOTIFY {
break
}
if nfy == nil {
Expand Down Expand Up @@ -182,7 +182,7 @@ func (c *Criu) doSwrkWithResp(reqType images.CriuReqType, opts *images.CriuOpts,
return resp, err
}

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

// Dump dumps a process
func (c *Criu) Dump(opts *images.CriuOpts, nfy Notify) error {
return c.doSwrk(images.CriuReqType_DUMP, opts, nfy)
func (c *Criu) Dump(opts *rpc.CriuOpts, nfy Notify) error {
return c.doSwrk(rpc.CriuReqType_DUMP, opts, nfy)
}

// Restore restores a process
func (c *Criu) Restore(opts *images.CriuOpts, nfy Notify) error {
return c.doSwrk(images.CriuReqType_RESTORE, opts, nfy)
func (c *Criu) Restore(opts *rpc.CriuOpts, nfy Notify) error {
return c.doSwrk(rpc.CriuReqType_RESTORE, opts, nfy)
}

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

// StartPageServer starts the page server
func (c *Criu) StartPageServer(opts *images.CriuOpts) error {
return c.doSwrk(images.CriuReqType_PAGE_SERVER, opts, nil)
func (c *Criu) StartPageServer(opts *rpc.CriuOpts) error {
return c.doSwrk(rpc.CriuReqType_PAGE_SERVER, opts, nil)
}

// StartPageServerChld starts the page server and returns PID and port
func (c *Criu) StartPageServerChld(opts *images.CriuOpts) (int, int, error) {
resp, err := c.doSwrkWithResp(images.CriuReqType_PAGE_SERVER_CHLD, opts, nil, nil)
func (c *Criu) StartPageServerChld(opts *rpc.CriuOpts) (int, int, error) {
resp, err := c.doSwrkWithResp(rpc.CriuReqType_PAGE_SERVER_CHLD, opts, nil, nil)
if err != nil {
return 0, 0, err
}
Expand All @@ -224,12 +224,12 @@ func (c *Criu) StartPageServerChld(opts *images.CriuOpts) (int, int, error) {
// GetCriuVersion executes the VERSION RPC call and returns the version
// as an integer. Major * 10000 + Minor * 100 + SubLevel
func (c *Criu) GetCriuVersion() (int, error) {
resp, err := c.doSwrkWithResp(images.CriuReqType_VERSION, nil, nil, nil)
resp, err := c.doSwrkWithResp(rpc.CriuReqType_VERSION, nil, nil, nil)
if err != nil {
return 0, err
}

if resp.GetType() != images.CriuReqType_VERSION {
if resp.GetType() != rpc.CriuReqType_VERSION {
return 0, fmt.Errorf("Unexpected CRIU RPC response")
}

Expand Down
5 changes: 3 additions & 2 deletions phaul/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/checkpoint-restore/go-criu/v6"
"github.com/checkpoint-restore/go-criu/v6/crit"
"github.com/checkpoint-restore/go-criu/v6/crit/images"
"github.com/checkpoint-restore/go-criu/v6/rpc"
"google.golang.org/protobuf/proto"
)

Expand Down Expand Up @@ -57,10 +58,10 @@ func isLastIter(iter int, stats *images.DumpStatsEntry, prevStats *images.DumpSt
// Migrate function
func (pc *Client) Migrate() error {
criu := criu.MakeCriu()
psi := images.CriuPageServerInfo{
psi := rpc.CriuPageServerInfo{
Fd: proto.Int32(int32(pc.cfg.Memfd)),
}
opts := &images.CriuOpts{
opts := &rpc.CriuOpts{
Pid: proto.Int32(int32(pc.cfg.Pid)),
LogLevel: proto.Int32(4),
LogFile: proto.String("pre-dump.log"),
Expand Down
6 changes: 3 additions & 3 deletions phaul/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"path/filepath"

"github.com/checkpoint-restore/go-criu/v6"
"github.com/checkpoint-restore/go-criu/v6/crit/images"
"github.com/checkpoint-restore/go-criu/v6/rpc"
"golang.org/x/sys/unix"
"google.golang.org/protobuf/proto"
)
Expand Down Expand Up @@ -37,10 +37,10 @@ func MakePhaulServer(c Config) (*Server, error) {
// StartIter phaul.Remote methods
func (s *Server) StartIter() error {
fmt.Printf("S: start iter\n")
psi := images.CriuPageServerInfo{
psi := rpc.CriuPageServerInfo{
Fd: proto.Int32(int32(s.cfg.Memfd)),
}
opts := &images.CriuOpts{
opts := &rpc.CriuOpts{
LogLevel: proto.Int32(4),
LogFile: proto.String("ps.log"),
Ps: &psi,
Expand Down
Loading