Use root dir when storing temporary checkpoint data

Signed-off-by: Kenfe-Mickael Laventure <mickael.laventure@gmail.com>
This commit is contained in:
Kenfe-Mickael Laventure
2017-08-03 14:15:09 -07:00
parent 642620cae3
commit 8700e23a10
6 changed files with 45 additions and 15 deletions

View File

@@ -81,6 +81,7 @@ func newCommand(binary, address string, debug bool, config Config, socket *os.Fi
args := []string{
"--namespace", config.Namespace,
"--address", address,
"--workdir", config.WorkDir,
}
if debug {
args = append(args, "--debug")
@@ -152,7 +153,7 @@ func WithConnect(ctx context.Context, config Config) (shim.ShimClient, io.Closer
// WithLocal uses an in process shim
func WithLocal(publisher events.Publisher) func(context.Context, Config) (shim.ShimClient, io.Closer, error) {
return func(ctx context.Context, config Config) (shim.ShimClient, io.Closer, error) {
service, err := NewService(config.Path, config.Namespace, publisher)
service, err := NewService(config.Path, config.Namespace, config.WorkDir, publisher)
if err != nil {
return nil, nil, err
}
@@ -165,6 +166,7 @@ type Config struct {
Path string
Namespace string
CgroupPath string
WorkDir string
}
// New returns a new shim client

View File

@@ -39,6 +39,8 @@ type initProcess struct {
// the reaper interface.
mu sync.Mutex
workDir string
id string
bundle string
console console.Console
@@ -54,7 +56,7 @@ type initProcess struct {
rootfs string
}
func newInitProcess(context context.Context, plat platform, path, namespace string, r *shimapi.CreateTaskRequest) (*initProcess, error) {
func newInitProcess(context context.Context, plat platform, path, namespace, workDir string, r *shimapi.CreateTaskRequest) (*initProcess, error) {
var success bool
if err := identifiers.Validate(r.ID); err != nil {
@@ -109,7 +111,8 @@ func newInitProcess(context context.Context, plat platform, path, namespace stri
stderr: r.Stderr,
terminal: r.Terminal,
},
rootfs: rootfs,
rootfs: rootfs,
workDir: workDir,
}
var (
err error
@@ -132,7 +135,7 @@ func newInitProcess(context context.Context, plat platform, path, namespace stri
opts := &runc.RestoreOpts{
CheckpointOpts: runc.CheckpointOpts{
ImagePath: r.Checkpoint,
WorkDir: filepath.Join(r.Bundle, "work"),
WorkDir: p.workDir,
ParentPath: r.ParentCheckpoint,
},
PidFile: pidFile,
@@ -310,10 +313,10 @@ func (p *initProcess) Checkpoint(context context.Context, r *shimapi.CheckpointT
if !options.Exit {
actions = append(actions, runc.LeaveRunning)
}
work := filepath.Join(p.bundle, "work")
work := filepath.Join(p.workDir, "criu-work")
defer os.RemoveAll(work)
if err := p.runtime.Checkpoint(context, p.id, &runc.CheckpointOpts{
WorkDir: work,
WorkDir: p.workDir,
ImagePath: r.Path,
AllowOpenTCP: options.OpenTcp,
AllowExternalUnixSockets: options.ExternalUnixSockets,

View File

@@ -30,7 +30,7 @@ var empty = &google_protobuf.Empty{}
const RuncRoot = "/run/containerd/runc"
// NewService returns a new shim service that can be used via GRPC
func NewService(path, namespace string, publisher events.Publisher) (*Service, error) {
func NewService(path, namespace, workDir string, publisher events.Publisher) (*Service, error) {
if namespace == "" {
return nil, fmt.Errorf("shim namespace cannot be empty")
}
@@ -41,6 +41,7 @@ func NewService(path, namespace string, publisher events.Publisher) (*Service, e
events: make(chan interface{}, 4096),
namespace: namespace,
context: context,
workDir: workDir,
}
if err := s.initPlatform(); err != nil {
return nil, errors.Wrap(err, "failed to initialized platform behavior")
@@ -69,11 +70,12 @@ type Service struct {
namespace string
context context.Context
workDir string
platform platform
}
func (s *Service) Create(ctx context.Context, r *shimapi.CreateTaskRequest) (*shimapi.CreateTaskResponse, error) {
process, err := newInitProcess(ctx, s.platform, s.path, s.namespace, r)
process, err := newInitProcess(ctx, s.platform, s.path, s.namespace, s.workDir, r)
if err != nil {
return nil, errdefs.ToGRPC(err)
}