From cc7b0630db03b503470781f2d7772bcaba3cb0a8 Mon Sep 17 00:00:00 2001 From: zhongjiawei Date: Thu, 12 Oct 2023 11:32:05 +0800 Subject: [PATCH] runc:freezer add delay after freeze --- ...when-force-deleting-a-non-exist-cont.patch | 61 +++++++++++++++ ...-runc-delete-invalid-cgroupinfo-logs.patch | 78 +++++++++++++++++++ ...init-unify-init-fix-its-error-logic.patch} | 0 ...-runc-freezer-add-delay-after-freeze.patch | 54 +++++++++++++ runc.spec | 10 ++- series.conf | 5 +- 6 files changed, 205 insertions(+), 3 deletions(-) create mode 100644 patch/0139-runc-ingore-error-when-force-deleting-a-non-exist-cont.patch create mode 100644 patch/0140-runc-delete-invalid-cgroupinfo-logs.patch rename patch/{0139-runc-libct-init-unify-init-fix-its-error-logic.patch => 0141-runc-libct-init-unify-init-fix-its-error-logic.patch} (100%) create mode 100644 patch/0142-runc-freezer-add-delay-after-freeze.patch diff --git a/patch/0139-runc-ingore-error-when-force-deleting-a-non-exist-cont.patch b/patch/0139-runc-ingore-error-when-force-deleting-a-non-exist-cont.patch new file mode 100644 index 0000000..d15548c --- /dev/null +++ b/patch/0139-runc-ingore-error-when-force-deleting-a-non-exist-cont.patch @@ -0,0 +1,61 @@ +From ec18dd94cf7df14516e95dc5b9023cff650c7196 Mon Sep 17 00:00:00 2001 +From: Antonio Murdaca +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 +--- + 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 + diff --git a/patch/0140-runc-delete-invalid-cgroupinfo-logs.patch b/patch/0140-runc-delete-invalid-cgroupinfo-logs.patch new file mode 100644 index 0000000..5eb9d60 --- /dev/null +++ b/patch/0140-runc-delete-invalid-cgroupinfo-logs.patch @@ -0,0 +1,78 @@ +From 7e71d4334b3d86deaec67474041ee949672d267b Mon Sep 17 00:00:00 2001 +From: zhongjiawei +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 + diff --git a/patch/0139-runc-libct-init-unify-init-fix-its-error-logic.patch b/patch/0141-runc-libct-init-unify-init-fix-its-error-logic.patch similarity index 100% rename from patch/0139-runc-libct-init-unify-init-fix-its-error-logic.patch rename to patch/0141-runc-libct-init-unify-init-fix-its-error-logic.patch diff --git a/patch/0142-runc-freezer-add-delay-after-freeze.patch b/patch/0142-runc-freezer-add-delay-after-freeze.patch new file mode 100644 index 0000000..2c9b149 --- /dev/null +++ b/patch/0142-runc-freezer-add-delay-after-freeze.patch @@ -0,0 +1,54 @@ +From f128e6e6c63a45543d833b8a4db5e691cfa0a0cc Mon Sep 17 00:00:00 2001 +From: Lu Jingxiao +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 + diff --git a/runc.spec b/runc.spec index 1a11720..4e5ed25 100644 --- a/runc.spec +++ b/runc.spec @@ -2,7 +2,7 @@ Name: docker-runc Version: 1.0.0.rc3 -Release: 214 +Release: 216 Summary: runc is a CLI tool for spawning and running containers according to the OCI specification. License: ASL 2.0 @@ -41,7 +41,13 @@ install -p -m 755 runc $RPM_BUILD_ROOT/%{_bindir}/runc %{_bindir}/runc %changelog -* Mon Sep 18 2023 zhongjiawei - 1.0.0.rc3-214 +* Thu Oct 12 2023 zhongjiawei - 1.0.0.rc3-216 +- Type:bugfix +- ID:NA +- SUG:NA +- DESC:freezer add delay after freeze + +* Mon Sep 18 2023 zhongjiawei - 1.0.0.rc3-215 - Type:bugfix - ID:NA - SUG:NA diff --git a/series.conf b/series.conf index e1fa5d4..9bd2154 100644 --- a/series.conf +++ b/series.conf @@ -130,4 +130,7 @@ 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 -- Gitee