forked from openshift/geard
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Created a global runtime checkpoint for libcontainer. Got rid of the …
…network specific runtime checkpoint. Docker-DCO-1.1-Signed-off-by: Vishnu Kannan <vishnuk@google.com> (github: vishh)
- Loading branch information
Showing
9 changed files
with
98 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package libcontainer | ||
|
||
import ( | ||
"encoding/json" | ||
"errors" | ||
"fmt" | ||
"io/ioutil" | ||
"os" | ||
"path/filepath" | ||
|
||
"github.com/docker/libcontainer/network" | ||
) | ||
|
||
// A checkpoint struct that will contain all runtime checkpointed information. | ||
type RuntimeCkpt struct { | ||
NetworkCkpt network.NetworkCkpt `json:"network_ckpt,omitempty"` | ||
} | ||
|
||
// The name of the network checkpoint file | ||
const runtimeCkptFile = "runtimeCkpt.json" | ||
|
||
var ErrRuntimeCkptNotFound = errors.New("Runtime Checkpoint not found") | ||
|
||
// Returns the path to the network checkpoint given the path to the base directory of network checkpoint. | ||
func getRuntimeCkptPath(basePath string) string { | ||
return filepath.Join(basePath, runtimeCkptFile) | ||
} | ||
|
||
// Updates the Runtime Checkpoint with current checkpoint information from all the subsystems. | ||
func UpdateRuntimeCkpt(basePath string) error { | ||
runtimeCkpt := &RuntimeCkpt{ | ||
NetworkCkpt: *network.NetworkCkptImpl.GetNetworkCkpt(), | ||
} | ||
data, err := json.Marshal(runtimeCkpt) | ||
if err != nil { | ||
return fmt.Errorf("Failed to checkpoint runtime information - %s", err) | ||
} | ||
return ioutil.WriteFile(getRuntimeCkptPath(basePath), data, 0655) | ||
} | ||
|
||
// Loads and returns the rutime checkpointing existing inside basePath. Returns ErrRuntimeCkptNotFound | ||
// if the runtime checkpoint does not exist. | ||
func GetRuntimeCkpt(basePath string) (*RuntimeCkpt, error) { | ||
runtimeCkpt := &RuntimeCkpt{} | ||
checkpointPath := getRuntimeCkptPath(basePath) | ||
f, err := os.Open(checkpointPath) | ||
if err != nil { | ||
if os.IsNotExist(err) { | ||
return runtimeCkpt, ErrRuntimeCkptNotFound | ||
} | ||
return runtimeCkpt, err | ||
} | ||
defer f.Close() | ||
|
||
if err := json.NewDecoder(f).Decode(runtimeCkpt); err != nil { | ||
return runtimeCkpt, err | ||
} | ||
|
||
return runtimeCkpt, nil | ||
} | ||
|
||
// Deletes the runtime checkpoint under basePath | ||
func DeleteNetworkRuntimeInfo(basePath string) error { | ||
return os.Remove(getRuntimeCkptPath(basePath)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,63 +1,25 @@ | ||
package network | ||
|
||
import ( | ||
"encoding/json" | ||
"errors" | ||
"fmt" | ||
"io/ioutil" | ||
"os" | ||
"path/filepath" | ||
) | ||
|
||
// Struct describing the network specific checkpoint that will be maintained by libcontainer for all running containers | ||
// This is an internal checkpoint, so do not depend on it outside of libcontainer. | ||
type NetworkRuntimeInfo struct { | ||
type NetworkCkpt 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"` | ||
} | ||
|
||
// The name of the network checkpoint file | ||
const networkInfoFile = "network.json" | ||
|
||
var ErrNetworkRuntimeInfoNotFound = errors.New("Network Checkpoint not found") | ||
|
||
// Returns the path to the network checkpoint given the path to the base directory of network checkpoint. | ||
func getNetworkRuntimeInfoPath(basePath string) string { | ||
return filepath.Join(basePath, networkInfoFile) | ||
} | ||
type NetworkCkptIntImpl struct{} | ||
|
||
// Marshalls the input network runtime info struct into a json object and stores it inside basepath. | ||
func writeNetworkRuntimeInfo(networkInfo *NetworkRuntimeInfo, basePath string) error { | ||
data, err := json.Marshal(networkInfo) | ||
if err != nil { | ||
return fmt.Errorf("Failed to checkpoint network runtime information - %s", err) | ||
} | ||
return ioutil.WriteFile(getNetworkRuntimeInfoPath(basePath), data, 0655) | ||
} | ||
|
||
// Loads the network runtime info from the checkpoint and returns the unmarshaled content. | ||
func LoadNetworkRuntimeInfo(basePath string) (NetworkRuntimeInfo, error) { | ||
var networkRuntimeInfo NetworkRuntimeInfo | ||
checkpointPath := getNetworkRuntimeInfoPath(basePath) | ||
f, err := os.Open(checkpointPath) | ||
if err != nil { | ||
if os.IsNotExist(err) { | ||
return networkRuntimeInfo, ErrNetworkRuntimeInfoNotFound | ||
} | ||
return networkRuntimeInfo, err | ||
} | ||
defer f.Close() | ||
|
||
if err := json.NewDecoder(f).Decode(&networkRuntimeInfo); err != nil { | ||
return networkRuntimeInfo, err | ||
} | ||
var ( | ||
networkCkptInfo = &NetworkCkpt{} | ||
NetworkCkptImpl = &NetworkCkptIntImpl{} | ||
) | ||
|
||
return networkRuntimeInfo, nil | ||
func (NetworkCkptIntImpl) GetNetworkCkpt() *NetworkCkpt { | ||
return networkCkptInfo | ||
} | ||
|
||
// Deletes the network checkpoint under basePath | ||
func deleteNetworkRuntimeInfo(basePath string) error { | ||
return os.Remove(getNetworkRuntimeInfoPath(basePath)) | ||
func (NetworkCkptIntImpl) updateNetworkCkpt(n *NetworkCkpt) { | ||
networkCkptInfo = n | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package api | ||
package libcontainer | ||
|
||
import ( | ||
"github.com/docker/libcontainer/cgroups" | ||
|