toHost takes an id mapping and a remapped ID, and translates the ID to the mapped host ID. If no map is provided, then the translation assumes a 1-to-1 mapping and returns the passed in id #
(contID uint32, idMap []specs.LinuxIDMapping)
| 122 | // ID to the mapped host ID. If no map is provided, then the translation |
| 123 | // assumes a 1-to-1 mapping and returns the passed in id # |
| 124 | func toHost(contID uint32, idMap []specs.LinuxIDMapping) (uint32, error) { |
| 125 | if idMap == nil { |
| 126 | return contID, nil |
| 127 | } |
| 128 | for _, m := range idMap { |
| 129 | high, err := safeSum(m.ContainerID, m.Size) |
| 130 | if err != nil { |
| 131 | break |
| 132 | } |
| 133 | if contID >= m.ContainerID && contID < high { |
| 134 | hostID, err := safeSum(m.HostID, contID-m.ContainerID) |
| 135 | if err != nil || hostID == invalidID { |
| 136 | break |
| 137 | } |
| 138 | return hostID, nil |
| 139 | } |
| 140 | } |
| 141 | return invalidID, fmt.Errorf("container ID %d cannot be mapped to a host ID", contID) |
| 142 | } |
| 143 | |
| 144 | // safeSum returns the sum of x and y. or an error if the result overflows |
| 145 | func safeSum(x, y uint32) (uint32, error) { |