runc:sync some patches

This commit is contained in:
zhongjiawei 2023-10-24 17:28:50 +08:00
parent 3486910456
commit 9d0f29ef37
7 changed files with 253 additions and 2 deletions

View File

@ -0,0 +1,61 @@
From ec18dd94cf7df14516e95dc5b9023cff650c7196 Mon Sep 17 00:00:00 2001
From: Antonio Murdaca <runcom@redhat.com>
Date: Tue, 16 May 2017 22:17:34 +0200
Subject: [PATCH] Ignore error when force deleting a non-existing container
This patch mimics the behavior of "rm -rf" so that if a container
doesn't exist and you force delete it, it won't error out.
Signed-off-by: Antonio Murdaca <runcom@redhat.com>
---
delete.go | 6 +++++-
tests/integration/delete.bats | 5 +++++
2 files changed, 10 insertions(+), 1 deletion(-)
diff --git a/delete.go b/delete.go
index a2b14f3..6db2978 100644
--- a/delete.go
+++ b/delete.go
@@ -50,6 +50,7 @@ status of "ubuntu01" as "stopped" the following will delete resources held for
}
id := context.Args().First()
+ force := context.Bool("force")
container, err := getContainer(context)
if err != nil {
if lerr, ok := err.(libcontainer.Error); ok && lerr.Code() == libcontainer.ContainerNotExists {
@@ -59,6 +60,9 @@ status of "ubuntu01" as "stopped" the following will delete resources held for
if e := os.RemoveAll(path); e != nil {
fmt.Fprintf(os.Stderr, "remove %s: %v\n", path, e)
}
+ if force {
+ return nil
+ }
}
return err
}
@@ -72,7 +76,7 @@ status of "ubuntu01" as "stopped" the following will delete resources held for
case libcontainer.Created:
return killContainer(container)
default:
- if context.Bool("force") {
+ if force {
return killContainer(container)
} else {
return fmt.Errorf("cannot delete container %s that is not stopped: %s\n", id, s)
diff --git a/tests/integration/delete.bats b/tests/integration/delete.bats
index 2c11e79..90a4f47 100644
--- a/tests/integration/delete.bats
+++ b/tests/integration/delete.bats
@@ -50,3 +50,8 @@ function teardown() {
runc state test_busybox
[ "$status" -ne 0 ]
}
+
+@test "runc delete --force ignore not exist" {
+ runc delete --force notexists
+ [ "$status" -eq 0 ]
+}
--
2.33.0

View File

@ -0,0 +1,78 @@
From 7e71d4334b3d86deaec67474041ee949672d267b Mon Sep 17 00:00:00 2001
From: zhongjiawei <zhongjiawei1@huawei.com>
Date: Tue, 22 Aug 2023 17:38:24 +0800
Subject: [PATCH] runc:delete invalid cgroupinfo logs
---
libcontainer/container_linux.go | 1 -
libcontainer/standard_init_linux.go | 28 ----------------------------
2 files changed, 29 deletions(-)
diff --git a/libcontainer/container_linux.go b/libcontainer/container_linux.go
index 113dbf4..d678407 100644
--- a/libcontainer/container_linux.go
+++ b/libcontainer/container_linux.go
@@ -322,7 +322,6 @@ func (c *linuxContainer) start(process *Process) error {
}
if err := parent.start(); err != nil {
- printCgroupInfo(c.config.Cgroups.Path)
// terminate the process to ensure that it properly is reaped.
if err := parent.terminate(); err != nil {
logrus.Warnf("parent process terminate error: %v", err)
diff --git a/libcontainer/standard_init_linux.go b/libcontainer/standard_init_linux.go
index b4945c3..611b91d 100644
--- a/libcontainer/standard_init_linux.go
+++ b/libcontainer/standard_init_linux.go
@@ -4,15 +4,12 @@ package libcontainer
import (
"fmt"
- "io/ioutil"
"os"
"os/exec"
- "path/filepath"
"strings"
"syscall"
"time"
- "github.com/Sirupsen/logrus"
"github.com/opencontainers/runc/libcontainer/apparmor"
"github.com/opencontainers/runc/libcontainer/configs"
"github.com/opencontainers/runc/libcontainer/keys"
@@ -220,32 +217,7 @@ func (l *linuxStandardInit) Init() error {
// https://github.com/torvalds/linux/blob/v4.9/fs/exec.c#L1290-L1318
syscall.Close(l.stateDirFD)
if err := syscall.Exec(name, l.config.Args[0:], os.Environ()); err != nil {
- printCgroupInfo("")
return newSystemErrorWithCause(err, "exec user process")
}
return nil
}
-
-func printCgroupInfo(path string) {
- cgroupRoot := "/sys/fs/cgroup"
- infoFileList := []string{
- "/proc/meminfo",
- "/sys/fs/cgroup/memory/memory.stat",
- filepath.Join(cgroupRoot, "files", path, "files.limit"),
- filepath.Join(cgroupRoot, "files", path, "files.usage"),
- filepath.Join(cgroupRoot, "pids", path, "pids.max"),
- filepath.Join(cgroupRoot, "pids", path, "pids.current"),
- filepath.Join(cgroupRoot, "memory", path, "memory.usage_in_bytes"),
- filepath.Join(cgroupRoot, "memory", path, "memory.limit_in_bytes"),
- filepath.Join(cgroupRoot, "memory", path, "memory.stat"),
- filepath.Join(cgroupRoot, "cpu", path, "cpu.stat"),
- }
- for _, file := range infoFileList {
- printFileContent(file)
- }
-}
-
-func printFileContent(path string) {
- output, err := ioutil.ReadFile(path)
- logrus.Infof("content read from %s: %s, err: %v", path, string(output), err)
-}
--
2.33.0

View File

@ -0,0 +1,54 @@
From f128e6e6c63a45543d833b8a4db5e691cfa0a0cc Mon Sep 17 00:00:00 2001
From: Lu Jingxiao <lujingxiao@huawei.com>
Date: Thu, 14 Sep 2023 11:44:43 +0800
Subject: [PATCH] [Huawei] freezer: add delay after freeze
reason: add delay after freeze and add a debug print.
backport from upstream manually with:
Conflict:NA
Reference:
https://github.com/opencontainers/runc/commit/524abc59f46373a175b97bd07c4c7eccf5594cc6
https://github.com/opencontainers/runc/commit/d1007b08a33ae63bb695fcb3244300c9bba2658a
---
libcontainer/cgroups/fs/freezer.go | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/libcontainer/cgroups/fs/freezer.go b/libcontainer/cgroups/fs/freezer.go
index 40f70c13..181caad1 100644
--- a/libcontainer/cgroups/fs/freezer.go
+++ b/libcontainer/cgroups/fs/freezer.go
@@ -8,6 +8,7 @@ import (
"strings"
"time"
+ "github.com/Sirupsen/logrus"
"github.com/opencontainers/runc/libcontainer/cgroups"
"github.com/opencontainers/runc/libcontainer/configs"
)
@@ -42,11 +43,21 @@ func (s *FreezerGroup) Set(path string, cgroup *configs.Cgroup) error {
if err := writeFile(path, "freezer.state", string(configs.Frozen)); err != nil {
return err
}
+ if i%25 == 24 {
+ // Occasional short sleep before reading
+ // the state back also improves the chances to
+ // succeed in freezing in case of a very slow
+ // system.
+ time.Sleep(10 * time.Microsecond)
+ }
state, err := readFile(path, "freezer.state")
if err != nil {
return err
}
if strings.TrimSpace(state) == string(configs.Frozen) {
+ if i > 1 {
+ logrus.Debugf("frozen after %d retries", i)
+ }
return nil
}
time.Sleep(1 * time.Millisecond)
--
2.23.0

View File

@ -0,0 +1,48 @@
From b8980e0d96ccf21bdda4254f4151097b2815269e Mon Sep 17 00:00:00 2001
From: zhongjiawei <zhongjiawei1@huawei.com>
Date: Tue, 24 Oct 2023 16:51:22 +0800
Subject: [PATCH] runc:runc:fix update rt-runtime-us and rt-period-us failed
---
libcontainer/cgroups/fs/cpu.go | 20 +++++++++++++++-----
1 file changed, 15 insertions(+), 5 deletions(-)
diff --git a/libcontainer/cgroups/fs/cpu.go b/libcontainer/cgroups/fs/cpu.go
index b712bd0..5176719 100644
--- a/libcontainer/cgroups/fs/cpu.go
+++ b/libcontainer/cgroups/fs/cpu.go
@@ -54,16 +54,26 @@ func (s *CpuGroup) ApplyDir(path string, cgroup *configs.Cgroup, pid int) error
}
func (s *CpuGroup) SetRtSched(path string, cgroup *configs.Cgroup) error {
- if cgroup.Resources.CpuRtPeriod != 0 {
- if err := writeFile(path, "cpu.rt_period_us", strconv.FormatUint(cgroup.Resources.CpuRtPeriod, 10)); err != nil {
- return err
+ var err error
+ if cgroup.Resources.CpuRtRuntime != 0 {
+ if err = writeFile(path, "cpu.rt_runtime_us", strconv.FormatInt(cgroup.Resources.CpuRtRuntime, 10)); err != nil {
+ if cgroup.Resources.CpuRtPeriod != 0 {
+ if err = writeFile(path, "cpu.rt_period_us", strconv.FormatUint(cgroup.Resources.CpuRtPeriod, 10)); err != nil {
+ return err
+ }
+ }
+ if err = writeFile(path, "cpu.rt_runtime_us", strconv.FormatInt(cgroup.Resources.CpuRtRuntime, 10)); err != nil {
+ return err
+ }
+ return nil
}
}
- if cgroup.Resources.CpuRtRuntime != 0 {
- if err := writeFile(path, "cpu.rt_runtime_us", strconv.FormatInt(cgroup.Resources.CpuRtRuntime, 10)); err != nil {
+ if cgroup.Resources.CpuRtPeriod != 0 {
+ if err = writeFile(path, "cpu.rt_period_us", strconv.FormatUint(cgroup.Resources.CpuRtPeriod, 10)); err != nil {
return err
}
}
+
return nil
}
--
2.33.0

View File

@ -2,7 +2,7 @@
Name: docker-runc
Version: 1.0.0.rc3
Release: 214
Release: 217
Summary: runc is a CLI tool for spawning and running containers according to the OCI specification.
License: ASL 2.0
@ -41,6 +41,12 @@ install -p -m 755 runc $RPM_BUILD_ROOT/%{_bindir}/runc
%{_bindir}/runc
%changelog
* Tue Oct 24 2023 zhongjiawei<zhongjiawei1@huawei.com> - 1.0.0.rc3-217
- Type:bugfix
- ID:NA
- SUG:NA
- DESC:sync some patches
* Mon Sep 18 2023 zhongjiawei<zhongjiawei1@huawei.com> - 1.0.0.rc3-214
- Type:bugfix
- ID:NA

View File

@ -130,4 +130,8 @@
0136-runc-run-resolve-tmpfs-mount-dest-in-container-scope.patch
0137-runc-Prohibit-proc-and-sys-to-be-symlinks.patch
0138-runc-libct-fix-shared-pidns-detection.patch
0139-runc-libct-init-unify-init-fix-its-error-logic.patch
0139-runc-ingore-error-when-force-deleting-a-non-exist-cont.patch
0140-runc-delete-invalid-cgroupinfo-logs.patch
0141-runc-libct-init-unify-init-fix-its-error-logic.patch
0142-runc-freezer-add-delay-after-freeze.patch
0143-runc-fix-update-rt-runtime-us-and-rt-period-us-.patch