diff --git a/go.mod b/go.mod index 7924f69f3c1..16502de7b3e 100644 --- a/go.mod +++ b/go.mod @@ -14,7 +14,7 @@ require ( github.com/moby/sys/user v0.4.0 github.com/moby/sys/userns v0.1.0 github.com/mrunalp/fileutils v0.5.1 - github.com/opencontainers/cgroups v0.0.3 + github.com/opencontainers/cgroups v0.0.4 github.com/opencontainers/runtime-spec v1.2.2-0.20250401095657-e935f995dd67 github.com/opencontainers/selinux v1.12.0 github.com/seccomp/libseccomp-golang v0.11.0 diff --git a/go.sum b/go.sum index 91fdf138b16..87bb5a7f060 100644 --- a/go.sum +++ b/go.sum @@ -45,8 +45,8 @@ github.com/moby/sys/userns v0.1.0 h1:tVLXkFOxVu9A64/yh59slHVv9ahO9UIev4JZusOLG/g github.com/moby/sys/userns v0.1.0/go.mod h1:IHUYgu/kao6N8YZlp9Cf444ySSvCmDlmzUcYfDHOl28= github.com/mrunalp/fileutils v0.5.1 h1:F+S7ZlNKnrwHfSwdlgNSkKo67ReVf8o9fel6C3dkm/Q= github.com/mrunalp/fileutils v0.5.1/go.mod h1:M1WthSahJixYnrXQl/DFQuteStB1weuxD2QJNHXfbSQ= -github.com/opencontainers/cgroups v0.0.3 h1:Jc9dWh/0YLGjdy6J/9Ln8NM5BfTA4W2BY0GMozy3aDU= -github.com/opencontainers/cgroups v0.0.3/go.mod h1:s8lktyhlGUqM7OSRL5P7eAW6Wb+kWPNvt4qvVfzA5vs= +github.com/opencontainers/cgroups v0.0.4 h1:XVj8P/IHVms/j+7eh8ggdkTLAxjz84ZzuFyGoE28DR4= +github.com/opencontainers/cgroups v0.0.4/go.mod h1:s8lktyhlGUqM7OSRL5P7eAW6Wb+kWPNvt4qvVfzA5vs= github.com/opencontainers/runtime-spec v1.2.2-0.20250401095657-e935f995dd67 h1:Q+KewUGTMamIe6Q39xCD/T1NC1POmaTlWnhjikCrZHA= github.com/opencontainers/runtime-spec v1.2.2-0.20250401095657-e935f995dd67/go.mod h1:jwyrGlmzljRJv/Fgzds9SsS/C5hL+LL3ko9hs6T5lQ0= github.com/opencontainers/selinux v1.12.0 h1:6n5JV4Cf+4y0KNXW48TLj5DwfXpvWlxXplUkdTrmPb8= diff --git a/vendor/github.com/opencontainers/cgroups/fs2/freezer.go b/vendor/github.com/opencontainers/cgroups/fs2/freezer.go index f0192f0955d..6307e68db7e 100644 --- a/vendor/github.com/opencontainers/cgroups/fs2/freezer.go +++ b/vendor/github.com/opencontainers/cgroups/fs2/freezer.go @@ -53,12 +53,9 @@ func setFreezer(dirPath string, state cgroups.FreezerState) error { func getFreezer(dirPath string) (cgroups.FreezerState, error) { fd, err := cgroups.OpenFile(dirPath, "cgroup.freeze", unix.O_RDONLY) if err != nil { - // If the kernel is too old, then we just treat the freezer as being in - // an "undefined" state. - if os.IsNotExist(err) || errors.Is(err, unix.ENODEV) { - err = nil - } - return cgroups.Undefined, err + // If the kernel is too old, then we just treat the freezer as + // being in an "undefined" state and ignore the error. + return cgroups.Undefined, ignoreNotExistOrNoDeviceError(err) } defer fd.Close() @@ -67,11 +64,15 @@ func getFreezer(dirPath string) (cgroups.FreezerState, error) { func readFreezer(dirPath string, fd *os.File) (cgroups.FreezerState, error) { if _, err := fd.Seek(0, 0); err != nil { - return cgroups.Undefined, err + // If the cgroup path is deleted at this point, then we just treat the freezer as + // being in an "undefined" state and ignore the error. + return cgroups.Undefined, ignoreNotExistOrNoDeviceError(err) } state := make([]byte, 2) if _, err := fd.Read(state); err != nil { - return cgroups.Undefined, err + // If the cgroup path is deleted at this point, then we just treat the freezer as + // being in an "undefined" state and ignore the error. + return cgroups.Undefined, ignoreNotExistOrNoDeviceError(err) } switch string(state) { case "0\n": @@ -83,6 +84,21 @@ func readFreezer(dirPath string, fd *os.File) (cgroups.FreezerState, error) { } } +// ignoreNotExistOrNoDeviceError checks if the error is either a "not exist" error +// or a "no device" error, and returns nil in those cases. Otherwise, it returns the error. +func ignoreNotExistOrNoDeviceError(err error) error { + // We can safely ignore the error in the following two common situations: + // 1. The cgroup path does not exist at the time of opening(eg: the kernel is too old) + // — indicated by os.IsNotExist. + // 2. The cgroup path is deleted during the seek/read operation — indicated by + // errors.Is(err, unix.ENODEV). + // These conditions are expected and do not require special handling. + if os.IsNotExist(err) || errors.Is(err, unix.ENODEV) { + return nil + } + return err +} + // waitFrozen polls cgroup.events until it sees "frozen 1" in it. func waitFrozen(dirPath string) (cgroups.FreezerState, error) { fd, err := cgroups.OpenFile(dirPath, "cgroup.events", unix.O_RDONLY) diff --git a/vendor/github.com/opencontainers/cgroups/fs2/hugetlb.go b/vendor/github.com/opencontainers/cgroups/fs2/hugetlb.go index 8e1ac874a58..bab9b556872 100644 --- a/vendor/github.com/opencontainers/cgroups/fs2/hugetlb.go +++ b/vendor/github.com/opencontainers/cgroups/fs2/hugetlb.go @@ -43,10 +43,11 @@ func setHugeTlb(dirPath string, r *cgroups.Resources) error { func statHugeTlb(dirPath string, stats *cgroups.Stats) error { hugetlbStats := cgroups.HugetlbStats{} rsvd := ".rsvd" + for _, pagesize := range cgroups.HugePageSizes() { + prefix := "hugetlb." + pagesize again: - prefix := "hugetlb." + pagesize + rsvd - value, err := fscommon.GetCgroupParamUint(dirPath, prefix+".current") + value, err := fscommon.GetCgroupParamUint(dirPath, prefix+rsvd+".current") if err != nil { if rsvd != "" && errors.Is(err, os.ErrNotExist) { rsvd = "" diff --git a/vendor/modules.txt b/vendor/modules.txt index 0d039051384..d7990d2a80f 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -51,7 +51,7 @@ github.com/moby/sys/userns # github.com/mrunalp/fileutils v0.5.1 ## explicit; go 1.13 github.com/mrunalp/fileutils -# github.com/opencontainers/cgroups v0.0.3 +# github.com/opencontainers/cgroups v0.0.4 ## explicit; go 1.23.0 github.com/opencontainers/cgroups github.com/opencontainers/cgroups/devices