From 7a012fe3b5163c5a9bf90721c9f6a60ee0f9a541 Mon Sep 17 00:00:00 2001 From: root Date: Thu, 23 Apr 2015 20:16:47 +0000 Subject: [PATCH] Allow dumped image to be transferred to a criu page server --page-server to specify the IP address of criu page server --port to specify the port of the criu page server Docker-DCO-1.1-Signed-off-by: Hui Kang --- container_linux.go | 8 ++++++++ criu_opts.go | 20 +++++++++++++------- nsinit/checkpoint.go | 29 +++++++++++++++++++++++++++-- 3 files changed, 48 insertions(+), 9 deletions(-) diff --git a/container_linux.go b/container_linux.go index 2793bad0..50bbd749 100644 --- a/container_linux.go +++ b/container_linux.go @@ -340,6 +340,14 @@ func (c *linuxContainer) Checkpoint(criuOpts *CriuOpts) error { ExtUnixSk: proto.Bool(criuOpts.ExternalUnixConnections), } + // append optional criu opts, e.g., page-server and port + if criuOpts.Ps.Address != "" && criuOpts.Ps.Port != 0 { + rpcOpts.Ps = &criurpc.CriuPageServerInfo{ + Address: proto.String(criuOpts.Ps.Address), + Port: proto.Int32(criuOpts.Ps.Port), + } + } + t := criurpc.CriuReqType_DUMP req := criurpc.CriuReq{ Type: &t, diff --git a/criu_opts.go b/criu_opts.go index c2474030..f898ceb2 100644 --- a/criu_opts.go +++ b/criu_opts.go @@ -1,10 +1,16 @@ package libcontainer -type CriuOpts struct { - ImagesDirectory string // directory for storing image files - WorkDirectory string // directory to cd and write logs/pidfiles/stats to - LeaveRunning bool // leave container in running state after checkpoint - TcpEstablished bool // checkpoint/restore established TCP connections - ExternalUnixConnections bool // allow external unix connections - ShellJob bool // allow to dump and restore shell jobs +type CriuPageServerInfo struct { + Address string // IP address of CRIU page server + Port int32 // port number of CRIU page server +} + +type CriuOpts struct { + ImagesDirectory string // directory for storing image files + WorkDirectory string // directory to cd and write logs/pidfiles/stats to + LeaveRunning bool // leave container in running state after checkpoint + TcpEstablished bool // checkpoint/restore established TCP connections + ExternalUnixConnections bool // allow external unix connections + ShellJob bool // allow to dump and restore shell jobs + Ps *CriuPageServerInfo // allow to dump to criu page server } diff --git a/nsinit/checkpoint.go b/nsinit/checkpoint.go index 39290cb9..242c8300 100644 --- a/nsinit/checkpoint.go +++ b/nsinit/checkpoint.go @@ -2,6 +2,7 @@ package main import ( "fmt" + "strconv" "github.com/codegangsta/cli" "github.com/docker/libcontainer" ) @@ -17,6 +18,8 @@ var checkpointCommand = cli.Command{ cli.BoolFlag{Name: "tcp-established", Usage: "allow open tcp connections"}, cli.BoolFlag{Name: "ext-unix-sk", Usage: "allow external unix sockets"}, cli.BoolFlag{Name: "shell-job", Usage: "allow shell jobs"}, + cli.StringFlag{Name: "page-server", Value: "", Usage: "IP address of the page server"}, + cli.StringFlag{Name: "port", Value: "", Usage: "port number of the page server"}, }, Action: func(context *cli.Context) { imagePath := context.String("image-path") @@ -28,14 +31,36 @@ var checkpointCommand = cli.Command{ if err != nil { fatal(err) } - if err := container.Checkpoint(&libcontainer.CriuOpts{ + + // these are the mandatory criu options for a container + criuOpts := &libcontainer.CriuOpts{ ImagesDirectory: imagePath, WorkDirectory: context.String("work-path"), LeaveRunning: context.Bool("leave-running"), TcpEstablished: context.Bool("tcp-established"), ExternalUnixConnections: context.Bool("ext-unix-sk"), ShellJob: context.Bool("shell-job"), - }); err != nil { + } + + // xxx following criu opts are optional + // The dump image can be sent to a criu page server + var port string + if psAddress := context.String("page-server"); psAddress != "" { + if port = context.String("port"); port == "" { + fatal(fmt.Errorf("The --port number isn't specified")) + } + + port_int, err := strconv.Atoi(port) + if err != nil { + fatal(fmt.Errorf("Invalid port number")) + } + criuOpts.Ps = &libcontainer.CriuPageServerInfo{ + Address: psAddress, + Port: int32(port_int), + } + } + + if err := container.Checkpoint(criuOpts); err != nil { fatal(err) } },