MCPcopy
hub / github.com/opencontainers/runc / Load

Function Load

libcontainer/factory_linux.go:108–148  ·  view source on GitHub ↗

Load takes a path to the state directory (root) and an id of an existing container, and returns a Container object reconstructed from the saved state. This presents a read only view of the container.

(root, id string)

Source from the content-addressed store, hash-verified

106// container, and returns a Container object reconstructed from the saved
107// state. This presents a read only view of the container.
108func Load(root, id string) (*Container, error) {
109 if root == "" {
110 return nil, errors.New("root not set")
111 }
112 // when load, we need to check id is valid or not.
113 if err := validateID(id); err != nil {
114 return nil, err
115 }
116 stateDir, err := securejoin.SecureJoin(root, id)
117 if err != nil {
118 return nil, err
119 }
120 state, err := loadState(stateDir)
121 if err != nil {
122 return nil, err
123 }
124 r := &nonChildProcess{
125 processPid: state.InitProcessPid,
126 processStartTime: state.InitProcessStartTime,
127 fds: state.ExternalDescriptors,
128 }
129 cm, err := manager.NewWithPaths(state.Config.Cgroups, state.CgroupPaths)
130 if err != nil {
131 return nil, err
132 }
133 c := &Container{
134 initProcess: r,
135 initProcessStartTime: state.InitProcessStartTime,
136 id: id,
137 config: &state.Config,
138 cgroupManager: cm,
139 intelRdtManager: intelrdt.NewManager(&state.Config, id, state.IntelRdtPath),
140 stateDir: stateDir,
141 created: state.Created,
142 }
143 c.state = &loadedState{c: c}
144 if err := c.refreshState(); err != nil {
145 return nil, err
146 }
147 return c, nil
148}
149
150func loadState(root string) (*State, error) {
151 stateFilePath, err := securejoin.SecureJoin(root, stateFilename)

Callers 5

getContainerFunction · 0.92
getContainersFunction · 0.92
testCheckpointFunction · 0.92
TestFactoryLoadNotExistsFunction · 0.85
TestFactoryLoadContainerFunction · 0.85

Calls 4

refreshStateMethod · 0.95
NewManagerFunction · 0.92
validateIDFunction · 0.85
loadStateFunction · 0.85

Tested by 3

testCheckpointFunction · 0.74
TestFactoryLoadNotExistsFunction · 0.68
TestFactoryLoadContainerFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…