Browse code

vendor: github.com/opencontainers/runc v1.2.2

full diff: https://github.com/opencontainers/runc/compare/v1.2.0...v1.2.2

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>

Sebastiaan van Stijn authored on 2024/11/19 18:39:15
Showing 4 changed files
... ...
@@ -81,7 +81,7 @@ require (
81 81
 	github.com/morikuni/aec v1.0.0
82 82
 	github.com/opencontainers/go-digest v1.0.0
83 83
 	github.com/opencontainers/image-spec v1.1.0
84
-	github.com/opencontainers/runc v1.2.0
84
+	github.com/opencontainers/runc v1.2.2
85 85
 	github.com/opencontainers/runtime-spec v1.2.0
86 86
 	github.com/opencontainers/selinux v1.11.1
87 87
 	github.com/pelletier/go-toml v1.9.5
... ...
@@ -418,8 +418,8 @@ github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8
418 418
 github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM=
419 419
 github.com/opencontainers/image-spec v1.1.0 h1:8SG7/vwALn54lVB/0yZ/MMwhFrPYtpEHQb2IpWsCzug=
420 420
 github.com/opencontainers/image-spec v1.1.0/go.mod h1:W4s4sFTMaBeK1BQLXbG4AdM2szdn85PY75RI83NrTrM=
421
-github.com/opencontainers/runc v1.2.0 h1:qke7ZVCmJcKrJVY2iHJVC+0kql9uYdkusOPsQOOeBw4=
422
-github.com/opencontainers/runc v1.2.0/go.mod h1:/PXzF0h531HTMsYQnmxXkBD7YaGShm/2zcRB79dksUc=
421
+github.com/opencontainers/runc v1.2.2 h1:jTg3Vw2A5f0N9PoxFTEwUhvpANGaNPT3689Yfd/zaX0=
422
+github.com/opencontainers/runc v1.2.2/go.mod h1:/PXzF0h531HTMsYQnmxXkBD7YaGShm/2zcRB79dksUc=
423 423
 github.com/opencontainers/runtime-spec v1.0.3-0.20220825212826-86290f6a00fb/go.mod h1:jwyrGlmzljRJv/Fgzds9SsS/C5hL+LL3ko9hs6T5lQ0=
424 424
 github.com/opencontainers/runtime-spec v1.2.0 h1:z97+pHb3uELt/yiAWD691HNHQIF07bE7dzrbT927iTk=
425 425
 github.com/opencontainers/runtime-spec v1.2.0/go.mod h1:jwyrGlmzljRJv/Fgzds9SsS/C5hL+LL3ko9hs6T5lQ0=
... ...
@@ -251,27 +251,39 @@ again:
251 251
 // RemovePath aims to remove cgroup path. It does so recursively,
252 252
 // by removing any subdirectories (sub-cgroups) first.
253 253
 func RemovePath(path string) error {
254
-	// Try the fast path first.
254
+	// Try the fast path first; don't retry on EBUSY yet.
255 255
 	if err := rmdir(path, false); err == nil {
256 256
 		return nil
257 257
 	}
258 258
 
259
+	// There are many reasons why rmdir can fail, including:
260
+	// 1. cgroup have existing sub-cgroups;
261
+	// 2. cgroup (still) have some processes (that are about to vanish);
262
+	// 3. lack of permission (one example is read-only /sys/fs/cgroup mount,
263
+	//    in which case rmdir returns EROFS even for for a non-existent path,
264
+	//    see issue 4518).
265
+	//
266
+	// Using os.ReadDir here kills two birds with one stone: check if
267
+	// the directory exists (handling scenario 3 above), and use
268
+	// directory contents to remove sub-cgroups (handling scenario 1).
259 269
 	infos, err := os.ReadDir(path)
260
-	if err != nil && !os.IsNotExist(err) {
270
+	if err != nil {
271
+		if os.IsNotExist(err) {
272
+			return nil
273
+		}
261 274
 		return err
262 275
 	}
276
+	// Let's remove sub-cgroups, if any.
263 277
 	for _, info := range infos {
264 278
 		if info.IsDir() {
265
-			// We should remove subcgroup first.
266 279
 			if err = RemovePath(filepath.Join(path, info.Name())); err != nil {
267
-				break
280
+				return err
268 281
 			}
269 282
 		}
270 283
 	}
271
-	if err == nil {
272
-		err = rmdir(path, true)
273
-	}
274
-	return err
284
+	// Finally, try rmdir again, this time with retries on EBUSY,
285
+	// which may help with scenario 2 above.
286
+	return rmdir(path, true)
275 287
 }
276 288
 
277 289
 // RemovePaths iterates over the provided paths removing them.
... ...
@@ -415,26 +427,29 @@ func ConvertCPUSharesToCgroupV2Value(cpuShares uint64) uint64 {
415 415
 
416 416
 // ConvertMemorySwapToCgroupV2Value converts MemorySwap value from OCI spec
417 417
 // for use by cgroup v2 drivers. A conversion is needed since Resources.MemorySwap
418
-// is defined as memory+swap combined, while in cgroup v2 swap is a separate value.
418
+// is defined as memory+swap combined, while in cgroup v2 swap is a separate value,
419
+// so we need to subtract memory from it where it makes sense.
419 420
 func ConvertMemorySwapToCgroupV2Value(memorySwap, memory int64) (int64, error) {
420
-	// for compatibility with cgroup1 controller, set swap to unlimited in
421
-	// case the memory is set to unlimited, and swap is not explicitly set,
422
-	// treating the request as "set both memory and swap to unlimited".
423
-	if memory == -1 && memorySwap == 0 {
421
+	switch {
422
+	case memory == -1 && memorySwap == 0:
423
+		// For compatibility with cgroup1 controller, set swap to unlimited in
424
+		// case the memory is set to unlimited and the swap is not explicitly set,
425
+		// treating the request as "set both memory and swap to unlimited".
424 426
 		return -1, nil
425
-	}
426
-	if memorySwap == -1 || memorySwap == 0 {
427
-		// -1 is "max", 0 is "unset", so treat as is
427
+	case memorySwap == -1, memorySwap == 0:
428
+		// Treat -1 ("max") and 0 ("unset") swap as is.
428 429
 		return memorySwap, nil
429
-	}
430
-	// sanity checks
431
-	if memory == 0 || memory == -1 {
430
+	case memory == -1:
431
+		// Unlimited memory, so treat swap as is.
432
+		return memorySwap, nil
433
+	case memory == 0:
434
+		// Unset or unknown memory, can't calculate swap.
432 435
 		return 0, errors.New("unable to set swap limit without memory limit")
433
-	}
434
-	if memory < 0 {
436
+	case memory < 0:
437
+		// Does not make sense to subtract a negative value.
435 438
 		return 0, fmt.Errorf("invalid memory value: %d", memory)
436
-	}
437
-	if memorySwap < memory {
439
+	case memorySwap < memory:
440
+		// Sanity check.
438 441
 		return 0, errors.New("memory+swap limit should be >= memory limit")
439 442
 	}
440 443
 
... ...
@@ -988,7 +988,7 @@ github.com/opencontainers/go-digest/digestset
988 988
 github.com/opencontainers/image-spec/identity
989 989
 github.com/opencontainers/image-spec/specs-go
990 990
 github.com/opencontainers/image-spec/specs-go/v1
991
-# github.com/opencontainers/runc v1.2.0
991
+# github.com/opencontainers/runc v1.2.2
992 992
 ## explicit; go 1.22
993 993
 github.com/opencontainers/runc/libcontainer/cgroups
994 994
 github.com/opencontainers/runc/libcontainer/configs