MCPcopy
hub / github.com/containerd/containerd / toHost

Function toHost

internal/userns/idmap.go:124–142  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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 #
124func 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
145func safeSum(x, y uint32) (uint32, error) {

Callers 2

RootPairMethod · 0.85
ToHostMethod · 0.85

Calls 1

safeSumFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…