[CRIU] [PATCH 08/10] phaul: check an exit code of a page-server
Andrei Vagin
avagin at openvz.org
Wed Oct 18 02:59:19 MSK 2017
From: Andrei Vagin <avagin at virtuozzo.com>
Signed-off-by: Andrei Vagin <avagin at virtuozzo.com>
---
lib/go/src/criu/main.go | 47 ++++++++++++++++++++++++++++++++++-------------
phaul/src/phaul/server.go | 28 ++++++++++++++++++++++++----
phaul/src/test/main.go | 2 +-
3 files changed, 59 insertions(+), 18 deletions(-)
diff --git a/lib/go/src/criu/main.go b/lib/go/src/criu/main.go
index 13e63b10a..96905111a 100644
--- a/lib/go/src/criu/main.go
+++ b/lib/go/src/criu/main.go
@@ -73,6 +73,21 @@ func (c *Criu) sendAndRecv(req_b []byte) ([]byte, int, error) {
}
func (c *Criu) doSwrk(req_type rpc.CriuReqType, opts *rpc.CriuOpts, nfy CriuNotify) error {
+ resp, err := c.doSwrkWithResp(req_type, opts, nfy)
+ if err != nil {
+ return err
+ }
+ resp_type := resp.GetType()
+ if resp_type != req_type {
+ return errors.New("unexpected responce")
+ }
+
+ return nil
+}
+
+func (c *Criu) doSwrkWithResp(req_type rpc.CriuReqType, opts *rpc.CriuOpts, nfy CriuNotify) (*rpc.CriuResp, error) {
+ var resp *rpc.CriuResp
+
req := rpc.CriuReq{
Type: &req_type,
Opts: opts,
@@ -85,7 +100,7 @@ func (c *Criu) doSwrk(req_type rpc.CriuReqType, opts *rpc.CriuOpts, nfy CriuNoti
if c.swrk_cmd == nil {
err := c.Prepare()
if err != nil {
- return err
+ return nil, err
}
defer c.Cleanup()
@@ -94,34 +109,31 @@ func (c *Criu) doSwrk(req_type rpc.CriuReqType, opts *rpc.CriuOpts, nfy CriuNoti
for {
req_b, err := proto.Marshal(&req)
if err != nil {
- return err
+ return nil, err
}
resp_b, resp_s, err := c.sendAndRecv(req_b)
if err != nil {
- return err
+ return nil, err
}
- resp := &rpc.CriuResp{}
+ resp = &rpc.CriuResp{}
err = proto.Unmarshal(resp_b[:resp_s], resp)
if err != nil {
- return err
+ return nil, err
}
if !resp.GetSuccess() {
- return fmt.Errorf("operation failed (msg:%s err:%d)",
+ return resp, fmt.Errorf("operation failed (msg:%s err:%d)",
resp.GetCrErrmsg(), resp.GetCrErrno())
}
resp_type := resp.GetType()
- if resp_type == req_type {
- break
- }
if resp_type != rpc.CriuReqType_NOTIFY {
- return errors.New("unexpected responce")
+ break
}
if nfy == nil {
- return errors.New("unexpected notify")
+ return resp, errors.New("unexpected notify")
}
notify := resp.GetNotify()
@@ -149,7 +161,7 @@ func (c *Criu) doSwrk(req_type rpc.CriuReqType, opts *rpc.CriuOpts, nfy CriuNoti
}
if err != nil {
- return err
+ return resp, err
}
req = rpc.CriuReq{
@@ -158,7 +170,7 @@ func (c *Criu) doSwrk(req_type rpc.CriuReqType, opts *rpc.CriuOpts, nfy CriuNoti
}
}
- return nil
+ return resp, nil
}
func (c *Criu) Dump(opts rpc.CriuOpts, nfy CriuNotify) error {
@@ -176,3 +188,12 @@ func (c *Criu) PreDump(opts rpc.CriuOpts, nfy CriuNotify) error {
func (c *Criu) StartPageServer(opts rpc.CriuOpts) error {
return c.doSwrk(rpc.CriuReqType_PAGE_SERVER, &opts, nil)
}
+
+func (c *Criu) StartPageServerChld(opts rpc.CriuOpts) (int, int, error) {
+ resp, err := c.doSwrkWithResp(rpc.CriuReqType_PAGE_SERVER_CHLD, &opts, nil)
+ if err != nil {
+ return 0, 0, err
+ }
+
+ return int(resp.Ps.GetPid()), int(resp.Ps.GetPort()), nil
+}
diff --git a/phaul/src/phaul/server.go b/phaul/src/phaul/server.go
index 4b79dde51..0994fb982 100644
--- a/phaul/src/phaul/server.go
+++ b/phaul/src/phaul/server.go
@@ -2,6 +2,7 @@ package phaul
import (
"fmt"
+ "os"
"github.com/golang/protobuf/proto"
"github.com/checkpoint-restore/criu/lib/go/src/criu"
@@ -9,9 +10,10 @@ import (
)
type PhaulServer struct {
- cfg PhaulConfig
- imgs *images
- cr *criu.Criu
+ cfg PhaulConfig
+ imgs *images
+ cr *criu.Criu
+ process *os.Process
}
/*
@@ -55,10 +57,28 @@ func (s *PhaulServer) StartIter() error {
opts.ParentImg = proto.String(prev_p)
}
- return s.cr.StartPageServer(opts)
+ pid, _, err := s.cr.StartPageServerChld(opts)
+ if err != nil {
+ return err
+ }
+
+ s.process, err = os.FindProcess(pid)
+ if err != nil {
+ return err
+ }
+
+ return nil
}
func (s *PhaulServer) StopIter() error {
+ state, err := s.process.Wait()
+ if err != nil {
+ return nil
+ }
+
+ if !state.Success() {
+ return fmt.Errorf("page-server failed: %s", s)
+ }
return nil
}
diff --git a/phaul/src/test/main.go b/phaul/src/test/main.go
index 9656cee78..2f8d74a5d 100644
--- a/phaul/src/test/main.go
+++ b/phaul/src/test/main.go
@@ -177,7 +177,7 @@ func main() {
Memfd: fds[0],
Wdir: images_dir + "/local"})
if err != nil {
- fmt.Printf("Unable to run a client: %v\n", err);
+ fmt.Printf("Unable to run a client: %v\n", err)
os.Exit(1)
}
--
2.13.3
More information about the CRIU
mailing list