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)
| 106 | // container, and returns a Container object reconstructed from the saved |
| 107 | // state. This presents a read only view of the container. |
| 108 | func 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 | |
| 150 | func loadState(root string) (*State, error) { |
| 151 | stateFilePath, err := securejoin.SecureJoin(root, stateFilename) |
searching dependent graphs…