Skip to content

Commit

Permalink
RuntimeCkpt is now State and the checkpoint file is called state.json.
Browse files Browse the repository at this point in the history
Docker-DCO-1.1-Signed-off-by: Vishnu Kannan <vishnuk@google.com> (github: vishh)
  • Loading branch information
vishh committed Jun 25, 2014
1 parent 481552c commit edf1e85
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 119 deletions.
4 changes: 2 additions & 2 deletions api.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import (
)

// Returns all available stats for the given container.
func GetContainerStats(container *Config, runtimeCkpt *RuntimeCkpt) (*ContainerStats, error) {
func GetContainerStats(container *Config, state *State) (*ContainerStats, error) {
containerStats := NewContainerStats()
stats, err := fs.GetStats(container.Cgroups)
if err != nil {
return containerStats, err
}
containerStats.CgroupStats = stats
networkStats, err := network.GetStats(&runtimeCkpt.NetworkCkpt)
networkStats, err := network.GetStats(&state.NetworkState)
if err != nil {
return containerStats, err
}
Expand Down
65 changes: 0 additions & 65 deletions checkpoint.go

This file was deleted.

22 changes: 8 additions & 14 deletions namespaces/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,6 @@ func Exec(container *libcontainer.Config, term Terminal, rootfs, dataPath string
return -1, err
}

state := &libcontainer.State{
InitPid: command.Process.Pid,
InitStartTime: started,
}

if err := libcontainer.SaveState(dataPath, state); err != nil {
command.Process.Kill()
command.Wait()
return -1, err
}
defer libcontainer.DeleteState(dataPath)

// Do this before syncing with child so that no children
// can escape the cgroup
cleaner, err := SetupCgroups(container, command.Process.Pid)
Expand All @@ -87,12 +75,18 @@ func Exec(container *libcontainer.Config, term Terminal, rootfs, dataPath string
return -1, err
}

// Update the runtime checkpoint.
if err = libcontainer.UpdateRuntimeCkpt(dataPath); err != nil {
state := &libcontainer.State{
InitPid: command.Process.Pid,
InitStartTime: started,
NetworkState: *network.NetworkStateImpl.GetNetworkState(),
}

if err := libcontainer.SaveState(dataPath, state); err != nil {
command.Process.Kill()
command.Wait()
return -1, err
}
defer libcontainer.DeleteState(dataPath)

// Sync with child
syncPipe.Close()
Expand Down
25 changes: 0 additions & 25 deletions network/checkpoint.go

This file was deleted.

25 changes: 25 additions & 0 deletions network/state.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package network

// Struct describing the network specific runtime state that will be maintained by libcontainer for all running containers
// Do not depend on it outside of libcontainer.
type NetworkState struct {
// The name of the veth interface on the Host.
VethHost string `json:"veth_host,omitempty"`
// The name of the veth interface created inside the container for the child.
VethChild string `json:"veth_child,omitempty"`
}

type networkStateIntImpl struct{}

var (
networkState = &NetworkState{}
NetworkStateImpl = &networkStateIntImpl{}
)

func (networkStateIntImpl) GetNetworkState() *NetworkState {
return networkState
}

func (networkStateIntImpl) updateNetworkState(n *NetworkState) {
networkState = n
}
6 changes: 3 additions & 3 deletions network/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ type NetworkStats struct {
}

// Returns the network statistics for the network interfaces represented by the NetworkRuntimeInfo.
func GetStats(networkCkpt *NetworkCkpt) (NetworkStats, error) {
func GetStats(networkState *NetworkState) (NetworkStats, error) {
// This can happen if the network runtime information is missing - possible if the container was created by an old version of libcontainer.
if networkCkpt.VethHost == "" {
if networkState.VethHost == "" {
return NetworkStats{}, nil
}
data, err := readSysfsNetworkStats(networkCkpt.VethHost)
data, err := readSysfsNetworkStats(networkState.VethHost)
if err != nil {
return NetworkStats{}, err
}
Expand Down
8 changes: 4 additions & 4 deletions network/veth.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ func (v *Veth) Create(n *Network, nspid int, context map[string]string, dataPath
if err := SetInterfaceInNamespacePid(name2, nspid); err != nil {
return err
}
networkCkpt := NetworkCkptImpl.GetNetworkCkpt()
networkCkpt.VethHost = name1
networkCkpt.VethChild = name2
NetworkCkptImpl.updateNetworkCkpt(networkCkpt)
networkState := NetworkStateImpl.GetNetworkState()
networkState.VethHost = name1
networkState.VethChild = name2
NetworkStateImpl.updateNetworkState(networkState)
return nil
}

Expand Down
6 changes: 3 additions & 3 deletions nsinit/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func statsAction(context *cli.Context) {
log.Fatal(err)
}

runtimeCkpt, err := libcontainer.GetRuntimeCkpt(dataPath)
runtimeCkpt, err := libcontainer.GetState(dataPath)
if err != nil {
log.Fatal(err)
}
Expand All @@ -35,8 +35,8 @@ func statsAction(context *cli.Context) {
}

// returns the container stats in json format.
func getContainerStats(container *libcontainer.Config, runtimeCkpt *libcontainer.RuntimeCkpt) (string, error) {
stats, err := libcontainer.GetContainerStats(container, runtimeCkpt)
func getContainerStats(container *libcontainer.Config, state *libcontainer.State) (string, error) {
stats, err := libcontainer.GetContainerStats(container, state)
if err != nil {
return "", err
}
Expand Down
13 changes: 10 additions & 3 deletions state.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"encoding/json"
"os"
"path/filepath"

"github.com/docker/libcontainer/network"
)

// State represents a running container's state
Expand All @@ -12,12 +14,17 @@ type State struct {
InitPid int `json:"init_pid,omitempty"`
// InitStartTime is the init process start time
InitStartTime string `json:"init_start_time,omitempty"`
// Network runtime state.
NetworkState network.NetworkState `json:"network_state,omitempty"`
}

// The name of the runtime state file
const stateFile = "state.json"

// SaveState writes the container's runtime state to a state.json file
// in the specified path
func SaveState(basePath string, state *State) error {
f, err := os.Create(filepath.Join(basePath, "state.json"))
f, err := os.Create(filepath.Join(basePath, stateFile))
if err != nil {
return err
}
Expand All @@ -28,7 +35,7 @@ func SaveState(basePath string, state *State) error {

// GetState reads the state.json file for a running container
func GetState(basePath string) (*State, error) {
f, err := os.Open(filepath.Join(basePath, "state.json"))
f, err := os.Open(filepath.Join(basePath, stateFile))
if err != nil {
return nil, err
}
Expand All @@ -44,5 +51,5 @@ func GetState(basePath string) (*State, error) {

// DeleteState deletes the state.json file
func DeleteState(basePath string) error {
return os.Remove(filepath.Join(basePath, "state.json"))
return os.Remove(filepath.Join(basePath, stateFile))
}

0 comments on commit edf1e85

Please sign in to comment.