Skip to content

Commit

Permalink
Update checkpoint/restore to match changes in latest docker.
Browse files Browse the repository at this point in the history
Docker-DCO-1.1-Signed-off-by: Ross Boucher <[email protected]> (github: boucher)
  • Loading branch information
boucher committed Aug 28, 2015
1 parent 3045715 commit 090aedc
Show file tree
Hide file tree
Showing 13 changed files with 30 additions and 46 deletions.
3 changes: 2 additions & 1 deletion api/client/checkpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
3 changes: 2 additions & 1 deletion api/client/restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
6 changes: 3 additions & 3 deletions api/server/server_experimental_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion api/server/server_stub.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {

}

Expand Down
6 changes: 3 additions & 3 deletions daemon/checkpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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
}
4 changes: 2 additions & 2 deletions daemon/container_checkpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
2 changes: 1 addition & 1 deletion daemon/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions daemon/execdriver/lxc/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Expand Down
18 changes: 0 additions & 18 deletions daemon/execdriver/native/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions daemon/execdriver/native/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down
16 changes: 8 additions & 8 deletions daemon/inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}

Expand Down
6 changes: 3 additions & 3 deletions daemon/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
}
Expand Down Expand Up @@ -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/<ID>.
if err := m.container.ToDisk(); err != nil {
if err := m.container.toDisk(); err != nil {
logrus.Debugf("%s", err)
}
}
Expand Down
2 changes: 1 addition & 1 deletion docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"fmt"
"os"
"sort"

"github.com/Sirupsen/logrus"
"github.com/docker/docker/api/client"
Expand Down Expand Up @@ -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))

Expand Down

0 comments on commit 090aedc

Please sign in to comment.