From 090aedcef7b4d973f6d45a32702ad3501ce8da48 Mon Sep 17 00:00:00 2001 From: boucher Date: Wed, 5 Aug 2015 09:32:41 -0700 Subject: [PATCH] Update checkpoint/restore to match changes in latest docker. Docker-DCO-1.1-Signed-off-by: Ross Boucher (github: boucher) --- api/client/checkpoint.go | 3 ++- api/client/restore.go | 3 ++- api/server/server_experimental_unix.go | 6 +++--- api/server/server_stub.go | 2 +- daemon/checkpoint.go | 6 +++--- daemon/container_checkpoint.go | 4 ++-- daemon/daemon.go | 2 +- daemon/execdriver/lxc/driver.go | 4 ++-- daemon/execdriver/native/create.go | 18 ------------------ daemon/execdriver/native/driver.go | 4 ++-- daemon/inspect.go | 16 ++++++++-------- daemon/monitor.go | 6 +++--- docker/docker.go | 2 +- 13 files changed, 30 insertions(+), 46 deletions(-) diff --git a/api/client/checkpoint.go b/api/client/checkpoint.go index 02990d9499adb..24fed5f68b634 100644 --- a/api/client/checkpoint.go +++ b/api/client/checkpoint.go @@ -5,12 +5,13 @@ package client import ( "fmt" + Cli "github.com/docker/docker/cli" flag "github.com/docker/docker/pkg/mflag" "github.com/docker/docker/runconfig" ) func (cli *DockerCli) CmdCheckpoint(args ...string) error { - cmd := cli.Subcmd("checkpoint", []string{"CONTAINER [CONTAINER...]"}, "Checkpoint one or more running containers", true) + cmd := Cli.Subcmd("checkpoint", []string{"CONTAINER [CONTAINER...]"}, "Checkpoint one or more running containers", true) cmd.Require(flag.Min, 1) var ( diff --git a/api/client/restore.go b/api/client/restore.go index 013acb4cf04b0..bef78a262b54a 100644 --- a/api/client/restore.go +++ b/api/client/restore.go @@ -5,12 +5,13 @@ package client import ( "fmt" + Cli "github.com/docker/docker/cli" flag "github.com/docker/docker/pkg/mflag" "github.com/docker/docker/runconfig" ) func (cli *DockerCli) CmdRestore(args ...string) error { - cmd := cli.Subcmd("restore", []string{"CONTAINER [CONTAINER...]"}, "Restore one or more checkpointed containers", true) + cmd := Cli.Subcmd("restore", []string{"CONTAINER [CONTAINER...]"}, "Restore one or more checkpointed containers", true) cmd.Require(flag.Min, 1) var ( diff --git a/api/server/server_experimental_unix.go b/api/server/server_experimental_unix.go index b49c66ec793f2..d41f6b0413235 100644 --- a/api/server/server_experimental_unix.go +++ b/api/server/server_experimental_unix.go @@ -5,12 +5,12 @@ package server import ( "encoding/json" "fmt" - "net/http" "github.com/docker/docker/pkg/version" "github.com/docker/docker/runconfig" - ) + "net/http" +) -func addExperimentalRoutes(s *Server, m map[string]map[string]HttpApiFunc) { +func addExperimentalRoutes(s *Server, m map[string]map[string]HTTPAPIFunc) { m["POST"]["/containers/{name:.*}/checkpoint"] = s.postContainersCheckpoint m["POST"]["/containers/{name:.*}/restore"] = s.postContainersRestore } diff --git a/api/server/server_stub.go b/api/server/server_stub.go index ce6669da845be..6d93d21626dd1 100644 --- a/api/server/server_stub.go +++ b/api/server/server_stub.go @@ -2,7 +2,7 @@ package server -func addExperimentalRoutes(s *Server, m map[string]map[string]HttpApiFunc) { +func addExperimentalRoutes(s *Server, m map[string]map[string]HTTPAPIFunc) { } diff --git a/daemon/checkpoint.go b/daemon/checkpoint.go index a39662cc0f325..6842b2ae58a9e 100644 --- a/daemon/checkpoint.go +++ b/daemon/checkpoint.go @@ -19,7 +19,7 @@ func (daemon *Daemon) ContainerCheckpoint(name string, opts *runconfig.CriuConfi return fmt.Errorf("Cannot checkpoint container %s: %s", name, err) } - container.LogEvent("checkpoint") + container.logEvent("checkpoint") return nil } @@ -47,10 +47,10 @@ func (daemon *Daemon) ContainerRestore(name string, opts *runconfig.CriuConfig, } if err = container.Restore(opts, forceRestore); err != nil { - container.LogEvent("die") + container.logEvent("die") return fmt.Errorf("Cannot restore container %s: %s", name, err) } - container.LogEvent("restore") + container.logEvent("restore") return nil } diff --git a/daemon/container_checkpoint.go b/daemon/container_checkpoint.go index 77f3488fbf157..27b23377de48b 100644 --- a/daemon/container_checkpoint.go +++ b/daemon/container_checkpoint.go @@ -13,10 +13,10 @@ func (container *Container) Checkpoint(opts *runconfig.CriuConfig) error { } if opts.LeaveRunning == false { - container.ReleaseNetwork() + container.releaseNetwork() } - if err := container.ToDisk(); err != nil { + if err := container.toDisk(); err != nil { return fmt.Errorf("Cannot update config for container: %s", err) } diff --git a/daemon/daemon.go b/daemon/daemon.go index f8f53dbadef7b..02a995e78d80f 100644 --- a/daemon/daemon.go +++ b/daemon/daemon.go @@ -899,7 +899,7 @@ func (daemon *Daemon) Checkpoint(c *Container, opts *runconfig.CriuConfig) error func (daemon *Daemon) Restore(c *Container, pipes *execdriver.Pipes, restoreCallback execdriver.RestoreCallback, opts *runconfig.CriuConfig, forceRestore bool) (execdriver.ExitStatus, error) { // Mount the container's filesystem (daemon/graphdriver/aufs/aufs.go). - _, err := daemon.driver.Get(c.ID, c.GetMountLabel()) + _, err := daemon.driver.Get(c.ID, c.getMountLabel()) if err != nil { return execdriver.ExitStatus{ExitCode: 0}, err } diff --git a/daemon/execdriver/lxc/driver.go b/daemon/execdriver/lxc/driver.go index e8196316098ad..dce464b7937db 100644 --- a/daemon/execdriver/lxc/driver.go +++ b/daemon/execdriver/lxc/driver.go @@ -561,11 +561,11 @@ func (d *Driver) Unpause(c *execdriver.Command) error { return err } -func (d *driver) Checkpoint(c *execdriver.Command, opts *runconfig.CriuConfig) error { +func (d *Driver) Checkpoint(c *execdriver.Command, opts *runconfig.CriuConfig) error { return fmt.Errorf("Checkpointing lxc containers not supported yet\n") } -func (d *driver) Restore(c *execdriver.Command, pipes *execdriver.Pipes, restoreCallback execdriver.RestoreCallback, opts *runconfig.CriuConfig, forceRestore bool) (execdriver.ExitStatus, error) { +func (d *Driver) Restore(c *execdriver.Command, pipes *execdriver.Pipes, restoreCallback execdriver.RestoreCallback, opts *runconfig.CriuConfig, forceRestore bool) (execdriver.ExitStatus, error) { return execdriver.ExitStatus{ExitCode: 0}, fmt.Errorf("Restoring lxc containers not supported yet\n") } diff --git a/daemon/execdriver/native/create.go b/daemon/execdriver/native/create.go index 95c2fd03eb5fc..85f72f8c2cc83 100644 --- a/daemon/execdriver/native/create.go +++ b/daemon/execdriver/native/create.go @@ -113,24 +113,6 @@ func generateIfaceName() (string, error) { return "", errors.New("Failed to find name for new interface") } -// Re-create the container type from the image that was saved during checkpoint. -func (d *driver) createRestoreContainer(c *execdriver.Command, imageDir string) (*libcontainer.Config, error) { - // Read the container.json. - f1, err := os.Open(filepath.Join(imageDir, "container.json")) - if err != nil { - return nil, err - } - defer f1.Close() - - var container *libcontainer.Config - err = json.NewDecoder(f1).Decode(&container) - if err != nil { - return nil, err - } - - return container, nil -} - func (d *Driver) createNetwork(container *configs.Config, c *execdriver.Command) error { if c.Network == nil { return nil diff --git a/daemon/execdriver/native/driver.go b/daemon/execdriver/native/driver.go index f4f34095ee50a..2b54aa3ff68ce 100644 --- a/daemon/execdriver/native/driver.go +++ b/daemon/execdriver/native/driver.go @@ -313,7 +313,7 @@ func libcontainerCriuOpts(runconfigOpts *runconfig.CriuConfig) *libcontainer.Cri } } -func (d *driver) Checkpoint(c *execdriver.Command, opts *runconfig.CriuConfig) error { +func (d *Driver) Checkpoint(c *execdriver.Command, opts *runconfig.CriuConfig) error { active := d.activeContainers[c.ID] if active == nil { return fmt.Errorf("active container for %s does not exist", c.ID) @@ -329,7 +329,7 @@ func (d *driver) Checkpoint(c *execdriver.Command, opts *runconfig.CriuConfig) e return nil } -func (d *driver) Restore(c *execdriver.Command, pipes *execdriver.Pipes, restoreCallback execdriver.RestoreCallback, opts *runconfig.CriuConfig, forceRestore bool) (execdriver.ExitStatus, error) { +func (d *Driver) Restore(c *execdriver.Command, pipes *execdriver.Pipes, restoreCallback execdriver.RestoreCallback, opts *runconfig.CriuConfig, forceRestore bool) (execdriver.ExitStatus, error) { var ( cont libcontainer.Container err error diff --git a/daemon/inspect.go b/daemon/inspect.go index bb80a24ee3529..00518e9105bc9 100644 --- a/daemon/inspect.go +++ b/daemon/inspect.go @@ -53,14 +53,14 @@ func (daemon *Daemon) getInspectData(container *Container) (*types.ContainerJSON Running: container.State.Running, Paused: container.State.Paused, Checkpointed: container.State.Checkpointed, - Restarting: container.State.Restarting, - OOMKilled: container.State.OOMKilled, - Dead: container.State.Dead, - Pid: container.State.Pid, - ExitCode: container.State.ExitCode, - Error: container.State.Error, - StartedAt: container.State.StartedAt.Format(time.RFC3339Nano), - FinishedAt: container.State.FinishedAt.Format(time.RFC3339Nano), + Restarting: container.State.Restarting, + OOMKilled: container.State.OOMKilled, + Dead: container.State.Dead, + Pid: container.State.Pid, + ExitCode: container.State.ExitCode, + Error: container.State.Error, + StartedAt: container.State.StartedAt.Format(time.RFC3339Nano), + FinishedAt: container.State.FinishedAt.Format(time.RFC3339Nano), CheckpointedAt: container.State.CheckpointedAt.Format(time.RFC3339Nano), } diff --git a/daemon/monitor.go b/daemon/monitor.go index fede2fb70035b..ee250d33d96ec 100644 --- a/daemon/monitor.go +++ b/daemon/monitor.go @@ -220,7 +220,7 @@ func (m *containerMonitor) Restore(opts *runconfig.CriuConfig, forceRestore bool pipes := execdriver.NewPipes(m.container.stdin, m.container.stdout, m.container.stderr, m.container.Config.OpenStdin) - m.container.LogEvent("restore") + m.container.logEvent("restore") m.lastStartTime = time.Now() if exitCode, err = m.container.daemon.Restore(m.container, pipes, m.restoreCallback, opts, forceRestore); err != nil { logrus.Errorf("Error restoring container: %s, exitCode=%d", err, exitCode) @@ -232,7 +232,7 @@ func (m *containerMonitor) Restore(opts *runconfig.CriuConfig, forceRestore bool m.container.ExitCode = exitCode.ExitCode m.resetMonitor(err == nil && exitCode.ExitCode == 0) - m.container.LogEvent("die") + m.container.logEvent("die") m.resetContainer(true) return err } @@ -341,7 +341,7 @@ func (m *containerMonitor) restoreCallback(processConfig *execdriver.ProcessConf if restorePid != 0 { // Write config.json and hostconfig.json files // to /var/lib/docker/containers/. - if err := m.container.ToDisk(); err != nil { + if err := m.container.toDisk(); err != nil { logrus.Debugf("%s", err) } } diff --git a/docker/docker.go b/docker/docker.go index 4d3477110c03f..fb0a5240e6936 100644 --- a/docker/docker.go +++ b/docker/docker.go @@ -3,6 +3,7 @@ package main import ( "fmt" "os" + "sort" "github.com/Sirupsen/logrus" "github.com/docker/docker/api/client" @@ -35,7 +36,6 @@ func main() { help := "\nCommands:\n" - // TODO(tiborvass): no need to sort if we ensure dockerCommands is sorted allCommands := append(dockerCommands, experimentalCommands...) sort.Sort(byName(allCommands))