(id, cgroupManager, cgroupParent string)
| 228 | } |
| 229 | |
| 230 | func generateCgroupPath(id, cgroupManager, cgroupParent string) (string, error) { |
| 231 | var ( |
| 232 | path string |
| 233 | usingSystemd = cgroupManager == "systemd" |
| 234 | slice = "system.slice" |
| 235 | scopePrefix = ":nerdctl:" |
| 236 | ) |
| 237 | if rootlessutil.IsRootlessChild() { |
| 238 | slice = "user.slice" |
| 239 | } |
| 240 | |
| 241 | if cgroupParent == "" { |
| 242 | if usingSystemd { |
| 243 | // "slice:prefix:name" |
| 244 | path = slice + scopePrefix + id |
| 245 | } |
| 246 | // Nothing to do for the non-systemd case if a parent wasn't supplied, |
| 247 | // containerd already sets a default cgroup path as /<namespace>/<containerID> |
| 248 | return path, nil |
| 249 | } |
| 250 | |
| 251 | // If the user asked for a cgroup parent, we will use systemd, |
| 252 | // Docker uses the following: |
| 253 | // parent + prefix (in our case, nerdctl) + containerID. |
| 254 | // |
| 255 | // In the non systemd case, it's just /parent/containerID |
| 256 | if usingSystemd { |
| 257 | if len(cgroupParent) <= 6 || !strings.HasSuffix(cgroupParent, ".slice") { |
| 258 | return "", errors.New(`cgroup-parent for systemd cgroup should be a valid slice named as "xxx.slice"`) |
| 259 | } |
| 260 | path = cgroupParent + scopePrefix + id |
| 261 | } else { |
| 262 | path = filepath.Join(cgroupParent, id) |
| 263 | } |
| 264 | |
| 265 | return path, nil |
| 266 | } |
| 267 | |
| 268 | // ParseDevice parses the give device string into hostDevPath, containerPath and mode(defaults: "rwm"). |
| 269 | func ParseDevice(s string) (hostDevPath string, containerPath string, mode string, err error) { |
no test coverage detected
searching dependent graphs…