Skip to content

Commit dd06ea0

Browse files
committed
Move checkpoint methods into a separate container_checkpoint file.
Docker-DCO-1.1-Signed-off-by: Ross Boucher <[email protected]> (github: boucher)
1 parent 61d0ea1 commit dd06ea0

File tree

2 files changed

+84
-76
lines changed

2 files changed

+84
-76
lines changed

daemon/container.go

-76
Original file line numberDiff line numberDiff line change
@@ -620,62 +620,6 @@ func validateID(id string) error {
620620
return nil
621621
}
622622

623-
func (container *Container) Checkpoint(opts *runconfig.CriuConfig) error {
624-
if err := container.daemon.Checkpoint(container, opts); err != nil {
625-
return err
626-
}
627-
628-
if opts.LeaveRunning == false {
629-
container.ReleaseNetwork()
630-
}
631-
return nil
632-
}
633-
634-
func (container *Container) Restore(opts *runconfig.CriuConfig, forceRestore bool) error {
635-
var err error
636-
container.Lock()
637-
defer container.Unlock()
638-
639-
defer func() {
640-
if err != nil {
641-
container.setError(err)
642-
// if no one else has set it, make sure we don't leave it at zero
643-
if container.ExitCode == 0 {
644-
container.ExitCode = 128
645-
}
646-
container.toDisk()
647-
container.cleanup()
648-
}
649-
}()
650-
651-
if err := container.Mount(); err != nil {
652-
return err
653-
}
654-
if err = container.initializeNetworking(true); err != nil {
655-
return err
656-
}
657-
linkedEnv, err := container.setupLinkedContainers()
658-
if err != nil {
659-
return err
660-
}
661-
if err = container.setupWorkingDirectory(); err != nil {
662-
return err
663-
}
664-
665-
env := container.createDaemonEnvironment(linkedEnv)
666-
if err = populateCommand(container, env); err != nil {
667-
return err
668-
}
669-
670-
mounts, err := container.setupMounts()
671-
if err != nil {
672-
return err
673-
}
674-
675-
container.command.Mounts = mounts
676-
return container.waitForRestore(opts, forceRestore)
677-
}
678-
679623
func (container *Container) Copy(resource string) (io.ReadCloser, error) {
680624
container.Lock()
681625
defer container.Unlock()
@@ -845,26 +789,6 @@ func (container *Container) waitForStart() error {
845789
return nil
846790
}
847791

848-
func (container *Container) waitForRestore(opts *runconfig.CriuConfig, forceRestore bool) error {
849-
container.monitor = newContainerMonitor(container, container.hostConfig.RestartPolicy)
850-
851-
// After calling promise.Go() we'll have two goroutines:
852-
// - The current goroutine that will block in the select
853-
// below until restore is done.
854-
// - A new goroutine that will restore the container and
855-
// wait for it to exit.
856-
select {
857-
case <-container.monitor.restoreSignal:
858-
if container.ExitCode != 0 {
859-
return fmt.Errorf("restore process failed")
860-
}
861-
case err := <-promise.Go(func() error { return container.monitor.Restore(opts, forceRestore) }):
862-
return err
863-
}
864-
865-
return nil
866-
}
867-
868792
func (container *Container) GetProcessLabel() string {
869793
// even if we have a process label return "" if we are running
870794
// in privileged mode

daemon/container_checkpoint.go

+84
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
package daemon
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/docker/docker/pkg/promise"
7+
"github.com/docker/docker/runconfig"
8+
)
9+
10+
func (container *Container) Checkpoint(opts *runconfig.CriuConfig) error {
11+
if err := container.daemon.Checkpoint(container, opts); err != nil {
12+
return err
13+
}
14+
15+
if opts.LeaveRunning == false {
16+
container.ReleaseNetwork()
17+
}
18+
return nil
19+
}
20+
21+
func (container *Container) Restore(opts *runconfig.CriuConfig, forceRestore bool) error {
22+
var err error
23+
container.Lock()
24+
defer container.Unlock()
25+
26+
defer func() {
27+
if err != nil {
28+
container.setError(err)
29+
// if no one else has set it, make sure we don't leave it at zero
30+
if container.ExitCode == 0 {
31+
container.ExitCode = 128
32+
}
33+
container.toDisk()
34+
container.cleanup()
35+
}
36+
}()
37+
38+
if err := container.Mount(); err != nil {
39+
return err
40+
}
41+
if err = container.initializeNetworking(true); err != nil {
42+
return err
43+
}
44+
linkedEnv, err := container.setupLinkedContainers()
45+
if err != nil {
46+
return err
47+
}
48+
if err = container.setupWorkingDirectory(); err != nil {
49+
return err
50+
}
51+
52+
env := container.createDaemonEnvironment(linkedEnv)
53+
if err = populateCommand(container, env); err != nil {
54+
return err
55+
}
56+
57+
mounts, err := container.setupMounts()
58+
if err != nil {
59+
return err
60+
}
61+
62+
container.command.Mounts = mounts
63+
return container.waitForRestore(opts, forceRestore)
64+
}
65+
66+
func (container *Container) waitForRestore(opts *runconfig.CriuConfig, forceRestore bool) error {
67+
container.monitor = newContainerMonitor(container, container.hostConfig.RestartPolicy)
68+
69+
// After calling promise.Go() we'll have two goroutines:
70+
// - The current goroutine that will block in the select
71+
// below until restore is done.
72+
// - A new goroutine that will restore the container and
73+
// wait for it to exit.
74+
select {
75+
case <-container.monitor.restoreSignal:
76+
if container.ExitCode != 0 {
77+
return fmt.Errorf("restore process failed")
78+
}
79+
case err := <-promise.Go(func() error { return container.monitor.Restore(opts, forceRestore) }):
80+
return err
81+
}
82+
83+
return nil
84+
}

0 commit comments

Comments
 (0)